/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.sac.converters;

import edu.upn.sigemfi.sac.bc.ProductoSbsDelegate;
import edu.upn.sigemfi.sac.be.ProductoSbs;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

/**
 *
 * @author Colao
 */
public class ProductoSbsConverter implements Converter {

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String string) throws ConverterException {
        ProductoSbsDelegate delegado = new ProductoSbsDelegate();
        if (string == null) {
            return null;
        }
        try {
            Long codigo = Long.parseLong(string);
            if (codigo != null) {
                return delegado.buscar(codigo);
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object object) throws ConverterException {
        if (object == null) {
            return null;
        }
        if (object instanceof ProductoSbs) {
            ProductoSbs pro = (ProductoSbs) object;
            return pro.getIdProductoSbs().toString();
        }
        return null;
    }



}
